define('view/header/Header',[
  'template',
  'text!view/header/headerTpl.html'
],function(template,headerTpl){
  var Widget = function(){
    this.init();
  };

  Widget.prototype = {
    init:function(){
      this.buildHeader();
      this.InitData();
    },

    buildHeader: function(){
      var loginName = $.session.get("loginname");
      window.initUser = true;
      var unLogin = true;
      if(loginName) {
        unLogin = false;
      }
      var render = template.compile(headerTpl);
      var html = render({
        unLogin:unLogin
      });
      // $(html).appendTo(".top-bg");
      $('.top-bg').empty().append(html);
    },

    InitData: function(){
      var _self = this;
      if($.session.get("loginname")){
        $("#session_loginname").text($.session.get("loginname"));
      }
      if($.session.get("balance")){
        $("#session_balance").text($.session.get("balance"));
      }
      if($.session.get("messageCount")){
        $("#session_messageCount").text($.session.get("messageCount"));
      }
      $('#login').click(_self.loginCallback.bind(_self));

			$('#logout').click(function(){
				$.session.remove("loginname");
				window.initUser=false;
				_self.init();
				
				
			});
			
      this.myAccountToggle();//我的账户
      this.lottGameHover();//彩种选择下拉翻转
      setInterval(this.getnowtime,1000);
    },

    myAccountToggle: function() {
      var _self = this;
      var len = $("#myAccount").length;
      if(len < 1) {
          setTimeout(_self.myAccountToggle, 100);
          return;
      }
      $("#myAccount").hover(function(){
          $(".wdzh").toggle();
      });
    },

    lottGameHover: function() {
      var _self = this;
      var len = $("#lott-game").length;
      if(len < 1) {
          setTimeout(_self.lottGameHover, 100);
          return;
      }
      $("#lott-game").hover(function(){
          $(".czxiala").show();
      });
      $(".czxiala").mouseleave(function(){
          $(this).css({"display":"none"})
      });
      $(".nav").mouseleave(function(){
          $(".czxiala").css({"display":"none"})
      });

      $(".czxiala ul li").mouseover(function(){
          $(this).addClass("bounce animated").siblings().removeClass("bounce animated")
      });
    },

    getnowtime: function(){
      var mytime="";
      var myobj=new Date();
      mytime+=myobj.getFullYear()+"-"+(myobj.getMonth()+1)+"-"+myobj.getDate()+" "+myobj.getHours()+":"+myobj.getMinutes()+":"+myobj.getSeconds()
      $("#nowtime").text(mytime);
    },

    loginCallback: function() {
      var _self = this;
      var username = $('#username').val();
      var password = $('#password').val();
      if(username == "bolcc" && password == "a123456"){
        $.session.set('loginname',username);
        _self.init();
      } else {
        alert("用户名、密码错误.");
      }
    }
    
    
    
    
    
    
  };

  return Widget;
});


